<?php
/**
 * Assertion concernant le maximum de reservations possible par utilisateur
 * 
 * @package zfbook
 * @subpackage acl
 * @uses Zend_Acl_Assert_Interface 
 */
class Zfbook_Acl_AddReservationAssertion implements Zend_Acl_Assert_Interface
{
    /**
     * Utilisateur à vérifier
     *
     * @var integer
     */
    private $_userId;
    
    /**
     * Nombre maximum de reservations à vérifier
     *
     * @var integer
     */
    private $_maxReservationsAllowed;
    
    /**
     * Constructeur
     *
     * @param integer $userId
     * @param integer $maxReservationsAllowed
     */
    public function __construct($userId, $maxReservationsAllowed = 5)
    {
        $this->_userId = (int)$userId;
        $this->_maxReservationsAllowed = (int)$maxReservationsAllowed;
    }
    
    /**
     * Assertion
     *
     * @param Zend_Acl $acl
     * @param Zend_Acl_Role_Interface $role
     * @param Zend_Acl_Resource_Interface $resource
     * @param string $privilege
     * @return bool
     */
    public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
    {
        $Tuser = new TUser();
        return $Tuser->getReservationsCount($this->_userId) < $this->_maxReservationsAllowed;
    }
}
